// Copyright 2010 Alexandre Tristan St-Cyr <tristan.stcyr@gmail.com>

package com.codeplex.loadjava;

import com.codeplex.loadjava.model.Field;
import com.codeplex.loadjava.model.JavaClass;
import com.codeplex.loadjava.model.Method;
import com.codeplex.loadjava.model.TypeReference;

class JavaModelReaderVisitor {
	
	IJavaModelVisitor entityVisitor;
	
	public JavaModelReaderVisitor(IJavaModelVisitor entityVisitor) {
		this.entityVisitor = entityVisitor;
	}

	protected void visitType(TypeReference type) {
		assert(type != null);
		JavaClass typeClass = type.getJavaClass();
		if (typeClass != null)
			this.entityVisitor.visitClass(type.getJavaClass());
		this.entityVisitor.visitType(type);
	}
	
	protected void visitField(Field field) {
		this.entityVisitor.visitClass(field.getDeclaringClass());
		this.visitType(field.getType());
		this.entityVisitor.visitField(field);
	}

	protected void visitMethod(Method method) {
		this.entityVisitor.visitClass(method.getDeclaringClass());
		this.visitType(method.getReturnType());
		this.entityVisitor.visitMethod(method);
	}
}
